"""
@Author: ISSCA_NEW
@Time: 2025/3/14 19:11
@User: DELL
@File: 噪声码及相关函数.py
@Software: PyCharm
@Attention: 安耐毁誉，八风不动
            利、衰、毁、誉、称、讥、苦、乐
"""

import numpy as np
import matplotlib.pyplot as plt
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimSun']
mpl.rcParams['axes.unicode_minus'] = False
import scipy.io

# 加载.mat文件
mat_file = scipy.io.loadmat('xxxxxxGNSS-matlab-master/prn_codes/codes_L1CA')

# 查看文件中的变量
for variable_name in mat_file:
    print(variable_name)

# 访问特定变量的数据
specific_variable = mat_file['codes_L1CA']
print(specific_variable.shape)
specific_variable=specific_variable.T



#读取两个伪随机噪声码，如果相同，为自相关，不同为互相关
code1 = specific_variable[0]
code2 = specific_variable[1]
print(code1.shape)
# 计算互相关值
correlation = np.correlate(code1, code2, mode='full')
print(len(correlation))
# 显示结果
print(correlation.max(),correlation.min())
plt.figure(figsize=(10,8))

plt.plot(correlation)
plt.xlim((0,2050))
plt.ylim((-100,1050))
plt.xticks([i*250 for i in range(0,9)],[str(i*250) for i in range(0,9)],fontsize=20,family='Times New Roman')

plt.yticks([0,200,400,600,800,1000,],[str(i) for i in [0,200,400,600,800,1000,]],fontsize=20,family='Times New Roman')

plt.xlabel("码片",fontsize=40,)

plt.ylabel("相关值",fontsize=40,)
# plt.savefig("GPSL1CA码互相关.jpg",dpi=800)
plt.show()
